#!/bin/bash

# 导航服务多平台二进制文件构建脚本
# 用于构建不同操作系统和架构的可执行文件

echo "开始构建导航服务多平台二进制文件..."

# 创建exe目录
mkdir -p exe

# 清理旧的构建文件
echo "清理旧的构建文件..."
rm -f exe/navigation-service-*

# 构建Windows AMD64版本
echo "构建 Windows AMD64 版本..."
GOOS=windows GOARCH=amd64 go build -o exe/navigation-service-windows-amd64.exe main.go
if [ $? -eq 0 ]; then
    echo "✓ Windows AMD64 构建成功"
else
    echo "✗ Windows AMD64 构建失败"
fi

# 构建Windows ARM64版本
echo "构建 Windows ARM64 版本..."
GOOS=windows GOARCH=arm64 go build -o exe/navigation-service-windows-arm64.exe main.go
if [ $? -eq 0 ]; then
    echo "✓ Windows ARM64 构建成功"
else
    echo "✗ Windows ARM64 构建失败"
fi

# 构建Linux AMD64版本
echo "构建 Linux AMD64 版本..."
GOOS=linux GOARCH=amd64 go build -o exe/navigation-service-linux-amd64 main.go
if [ $? -eq 0 ]; then
    echo "✓ Linux AMD64 构建成功"
else
    echo "✗ Linux AMD64 构建失败"
fi

# 构建Linux ARM64版本
echo "构建 Linux ARM64 版本..."
GOOS=linux GOARCH=arm64 go build -o exe/navigation-service-linux-arm64 main.go
if [ $? -eq 0 ]; then
    echo "✓ Linux ARM64 构建成功"
else
    echo "✗ Linux ARM64 构建失败"
fi

# 构建macOS ARM64版本
echo "构建 macOS ARM64 版本..."
GOOS=darwin GOARCH=arm64 go build -o exe/navigation-service-macos-arm64 main.go
if [ $? -eq 0 ]; then
    echo "✓ macOS ARM64 构建成功"
else
    echo "✗ macOS ARM64 构建失败"
fi

# 显示构建结果
echo ""
echo "构建完成！生成的文件："
ls -la exe/

echo ""
echo "文件说明："
echo "- navigation-service-windows-amd64.exe: Windows 64位 (Intel/AMD)"
echo "- navigation-service-windows-arm64.exe: Windows ARM64 (如Surface Pro X)"
echo "- navigation-service-linux-amd64: Linux 64位 (Intel/AMD)"
echo "- navigation-service-linux-arm64: Linux ARM64 (如树莓派4、ARM服务器)"
echo "- navigation-service-macos-arm64: macOS ARM64 (如Mac M1/M2/M3芯片)"
